<template>
		<el-card style="height: 100%;">
				<el-button @click="input()" type="primary" style="margin: 25px 0;">
             新增
        </el-button>
				<el-dialog
				  title="提示"
				  :visible.sync="dialogVisible"
				  width="30%">
				<el-input v-model="form.name" placeholder="请输入题库名称"></el-input>
				 <el-divider></el-divider>
				    <el-button @click="dialogVisible = false">关 闭</el-button>
				    <el-button type="primary" @click="sunbmit()">确 定</el-button>
				  </span>
				</el-dialog>

			<el-table
			    ref="multipleTable"
			    :data="tableData"
			    tooltip-effect="dark"
			    style="width: 100%"
			    >
			    </el-table-column>
			    <el-table-column
			      label="题库名称号"
				prop="name"
			     >

			    </el-table-column>
			    <el-table-column
			      prop="danNums"

			      label="单选题数量"
			      >
			    </el-table-column>
			    <el-table-column
			      prop="duoNums"
			      label="多选题数量"
			      show-overflow-tooltip>
			    </el-table-column>
				<el-table-column
				  prop="panNums"
				  label="判断题数量"
				  show-overflow-tooltip>
				</el-table-column>
				<el-table-column
				  fixed="right"
				  label="操作"
				  >
				  <template slot-scope="scope">
				    <el-button @click="deletea(scope.row)" type="text" size="small">删除</el-button>
				  </template>
				</el-table-column>
			  </el-table>
		</el-card>
</template>

<script>
	 export default {
	    data() {
	      return {
          form:[{name:''}],
          tableData: [],
          multipleSelection: [],
          dialogVisible:false,
          danNums:0,
          duoNums:0,
          panNums:0,
          currentPage: 4,
	      }
	    },
		methods:{
			deletea(row) {

					  this.$ajax.post("/tiku/delete",{"id":row.id}).then(res=>{
						  if(res.data.success){
							  this.getList()
						  }
						  })
			},
			 handleSizeChange(val) {
			        console.log('每页 ${val} 条');
			      },
				 handleCurrentChange(val) {
				          console.log('当前页: ${val}');

				      },
			getList(){
				this.$ajax.post("/tiku/page",{}).then(res=>{
					if(res.data){
						var arr=new Array;
						for (let i = 0; i < res.data.data.rows.length; i++) {
							this.danNums=0;this.duoNums=0;
							this.panNums =0;
							for (let q = 0; q < res.data.data.rows[i].question.length; q++) {
								if(res.data.data.rows[i].question[q].type==1){
								  this.danNums++;
								}else if(res.data.data.rows[i].question[q].type==2){
									 this.duoNums++;
								}else{
									this.panNums++;
								}
							}

						arr.push({ 'id':res.data.data.rows[i].id, 'name': res.data.data.rows[i].name,"danNums":this.danNums,"duoNums":this.duoNums,"panNums":this.panNums})
						}
						this.tableData=arr
						console.log(this.tableData);
					}
				})
			},
			input(){
				this.dialogVisible=true
			},
			sunbmit(){
				this.$ajax.post("/tiku/save",{"name":this.form.name}).then(res=>{
					if(res.data.success){
					  this.$message({
					          message: '保存成功！',
					          type: 'success'
					        });
						this.getList()
					}
				})
				this.dialogVisible=false
			}
		},
		created() {
			this.getList()
		}
		}
</script>

<style>

</style>
